//
//  TurnOverModel.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/8.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

//营业额模型
//model得到的只是原始数据并不加工

import UIKit

class TurnOverModel: BaseModel {
    var sumPrice : Int = 0//
    var sumCommision : Int = 0
    var dataSrc : Array<TableCellModel> = []
    
    override init(array : Array<Dictionary<String,Any>>) {
        super.init(array: array)
        for item in array {
            if let comp = item["commission"] as? Int {
                sumCommision = comp + sumCommision
            }
            if let sumPric = item["final_price"] as? Int{
                sumPrice = sumPrice + sumPric
            }
            let mod = TableCellModel.init(source: item)
            dataSrc.append(mod)
        }
    }
    
    override init(source sourceDt: Dictionary<String, Any>?) {
        super.init(source: sourceDt)
        guard self.data != nil else {
            return
        }
        if let dataDic = self.data as? Dictionary<String,Any> {
            if let total = dataDic["sumPrice"] as? Int {
                sumPrice = total
            }
            if let commision = dataDic["sumCommission"] as? Int {
                sumCommision = commision
            }
            if let list = dataDic["list"] as? Array<Dictionary<String,Any>>{
                for item in list {
                    let mod = TableCellModel.init(source: item)
                    dataSrc.append(mod)
                }
            }
        }
        self.data = nil
    }
    
    deinit {
        print("turnover被释放")
    }
}
